<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAppVersionsTable extends Migration
{
    private const TABLE = 'app_versions';

    public function up()
    {
        if (Schema::connection('gameCenter')->hasTable(self::TABLE)) {
            return;
        }
        Schema::connection('gameCenter')->create(self::TABLE, function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('appid')->default(0)->comment('应用ID');
            $table->unsignedInteger('source')->default(0)->comment('渠道号');
            $table->unsignedTinyInteger('os')->default(0)->comment('系统类型 0安卓 1IOS');
            $table->string('minVer')->default('')->comment('最小版本号');
            $table->string('curVer')->default('')->comment('当前版本号');
            $table->string('url')->default('')->comment('下载URL');
            $table->timestamps();

            $table->index(['source', 'os']);
        });
        DB::connection('gameCenter')->statement("ALTER TABLE `tb_".self::TABLE."` comment '应用版本'");
    }

    public function down()
    {
        Schema::connection('gameCenter')->dropIfExists(self::TABLE);
    }
}
